#ifndef __IIC_H
#define __IIC_H
#include "gpio.h"
#include "stm32f4xx_hal.h" 

/**
 @ SCL  PB10
 @ SDA  PB11
**/
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 

#define GPIOB_ODR_Addr    (GPIOB_BASE+20)
#define GPIOB_IDR_Addr    (GPIOB_BASE+16)
#define PBout(n)   BIT_ADDR(GPIOB_ODR_Addr,n)  
#define PBin(n)    BIT_ADDR(GPIOB_IDR_Addr,n)   

   	   		   
//IO方向设置
#define SDA_IN()  {GPIOB->MODER&=~(3<<(11*2));GPIOB->MODER|=0<<11*2;}	//PB11输入模式
#define SDA_OUT() {GPIOB->MODER&=~(3<<(11*2));GPIOB->MODER|=1<<11*2;}   //PB11输出模式


#define IIC_SCL    	PBout(10) //SCL
#define IIC_SDA    	PBout(11) //SDA
#define MPU6050_AD0	PBout(14) //AD0

#define READ_SDA   PBin(11)  //输入SDA 




            			 
void IIC_Start(void);				
void IIC_Stop(void);	  			
void IIC_Send_Byte(uint8_t txd);			
unsigned char IIC_Read_Byte(unsigned char ack);
unsigned char IIC_Wait_Ack(void); 				
void IIC_Ack(void);					
void IIC_NAck(void);				


#endif
